package datasv.collegeQuery_datasv;

import data.datafactory.DatabaseOperator;
import resultmessage.CollegeQueryRM;

public class DeleteCourse {
	public static void main(String[] args) {
		System.out.println(new DeleteCourse().deleteCourse("001", "0010113010"));
		System.out.println("delete course test successfully");
	}
	public CollegeQueryRM deleteCourse(String collegeID,String courseID){
		return deleteInSql(collegeID, courseID);
	}
	private CollegeQueryRM deleteInSql(String collegeID,String courseID){
		DatabaseOperator op=new DatabaseOperator("college"+collegeID);
		if(!op.ifDatabaseExist()){
			return CollegeQueryRM.COLLEGE_NOT_EXIT;
		}
		if(op.ifIDExist("course_list", courseID)||!op.ifFormExist("course_student_list_"+courseID)){
			return CollegeQueryRM.COURSEID_NOT_EXIST;
		}
		if(op.deleteOneRow(courseID, "course_list")){
			if(!op.deleteForm("course_student_list_"+courseID)){
				System.out.println("delete course student list "+courseID +" error ..no such a form maybe");
			}
			return CollegeQueryRM.SUCCESS;
		}
		return CollegeQueryRM.COURSEID_NOT_EXIST;
	}
}
